#版本 注意，需要跟随版本号进行调整
version=1.0.2
#运行目录
code_path=$PWD
run_path=/root/s2b2b2c/service

mkdir -p ${run_path}

ps -ef | grep java | grep gateway | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep system-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep goods-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep user-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep order-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep payment-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep promotion-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep statistics-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep distribution-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep broadcast-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep auth-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep resource-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep supplier-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep im-service | grep -v 'grep' | awk '{print $2}' | xargs kill -9
ps -ef | grep java | grep consumer | grep -v 'grep' | awk '{print $2}' | xargs kill -9

mvServer() {
  if [ -e "$1" ]; then
    mv "$1" ${run_path}
  else
    echo "$1文件不存在"
  fi
}

rm -rf ${run_path}*.jar
mvServer "${code_path}"/gateway/target/gateway-$version.jar
mvServer "${code_path}"/service/system-service/target/system-service-$version.jar
mvServer "${code_path}"/service/goods-service/target/goods-service-$version.jar
mvServer "${code_path}"/service/user-service/target/user-service-$version.jar
mvServer "${code_path}"/service/order-service/target/order-service-$version.jar
mvServer "${code_path}"/service/payment-service/target/payment-service-$version.jar
mvServer "${code_path}"/service/promotion-service/target/promotion-service-$version.jar
mvServer "${code_path}"/service/statistics-service/target/statistics-service-$version.jar
mvServer "${code_path}"/service/distribution-service/target/distribution-service-$version.jar
mvServer "${code_path}"/service/broadcast-service/target/broadcast-service-$version.jar
mvServer "${code_path}"/service/auth-service/target/auth-service-$version.jar
mvServer "${code_path}"/service/resource-service/target/resource-service-$version.jar
mvServer "${code_path}"/service/supplier-service/target/supplier-service-$version.jar
mvServer "${code_path}"/service/im-service/target/im-service-$version.jar
mvServer "${code_path}"/service/consumer/target/consumer-$version.jar

if [ ! -d "${run_path}/logs" ]; then
  mkdir ${run_path}/logs
else
  echo "文件夹已经存在"
fi

nohup java -Xmx512m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/gateway-$version.jar >${run_path}/logs/gateway.out &
nohup java -Xmx512m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/system-service-$version.jar >${run_path}/logs/system-service.out &
nohup java -Xmx512m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/goods-service-$version.jar >${run_path}/logs/goods-service.out &
nohup java -Xmx512m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/user-service-$version.jar >${run_path}/logs/user-service.out &
nohup java -Xmx512m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/order-service-$version.jar >${run_path}/logs/order-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/payment-service-$version.jar >${run_path}/logs/payment-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/promotion-service-$version.jar >${run_path}/logs/promotion-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/statistics-service-$version.jar >${run_path}/logs/statistics-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/distribution-service-$version.jar >${run_path}/logs/distribution-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/broadcast-service-$version.jar >${run_path}/logs/broadcast-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/auth-service-$version.jar >${run_path}/logs/auth-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/resource-service-$version.jar >${run_path}/logs/resource-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/supplier-service-$version.jar >${run_path}/logs/supplier-service.out &
nohup java -Xmx256m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/im-service-$version.jar >${run_path}/logs/im-service.out &
nohup java -Xmx512m -Xms128m -Xss256k -jar --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED ${run_path}/consumer-$version.jar >${run_path}/logs/consumer.out &
echo "服务启动成功"
